package com.hbnu.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;


import java.util.Date;

@Component
@Aspect
public class LogTime {
    @Before("com.hbnu.aop.CommonPointcuts.inAop()")
    public void printTime(){
        System.out.println(new Date());
    }

    @AfterReturning("com.hbnu.aop.CommonPointcuts.inAop()")
    public void afterReturning(){
        System.out.println("后置通知");
    }

    @Around("execution(* com..aop.*.*())")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕通知,执行前");
        proceedingJoinPoint.proceed();
        System.out.println("环绕通知，执行后");
    }

    @After("execution(* com.hbnu.aop.UserService.register())")
    public void around() {
        System.out.println("最终通知");
    }

    @AfterThrowing("execution(* com.hbnu.aop.UserService.register())")
    public void afterThrow() {
        System.out.println("发生异常");
    }
}
